﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;
using LinqToBing.Bing.Wrapper.Interfaces;
using LinqToBing.Bing.Wrapper.Search;

namespace LinqToBing.Bing.Linq
{
    internal class ExpressionTreeModifier : ExpressionVisitor
    {
        private IQueryable<SearchResultBase> queryableResults;

        internal ExpressionTreeModifier(IQueryable<SearchResultBase> results)
        {
            this.queryableResults = results;
        }

        protected override Expression VisitConstant(ConstantExpression c)
        {
            // Replace the constant QueryableTerraServerData arg with the queryable Place collection.
            if (c.Type == typeof(QueryableLiveSearchResultBase<SearchResultBase>))
                return Expression.Constant(this.queryableResults);
            else
                return c;
        }
    }
}
